package com.example.wechat.csdnandroid.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.wechat.csdnandroid.R;

public class ListViewActivity extends AppCompatActivity {

    private ListView lvAlv;
    private String data[] = {"a", "b", "c", "d", "d", "e", "f", "g", "h", "i"};
    private static final String TAG = "ListViewActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);
        initView();
        initData();
    }


    private void initData() {
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
        lvAlv.setAdapter(arrayAdapter);
        lvAlv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.e(TAG, "onItemClick: "+position );
                Log.e(TAG, "onItemClick: "+data[position] );
            }
        });
    }

    private void initView() {
        lvAlv = (ListView) findViewById(R.id.lv_alv);
    }
}
